package spring.my_aop;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class PojoProxyInvocationHandler<T extends AbstractPojo> implements InvocationHandler {

    private T t;

    public PojoProxyInvocationHandler(T abstractPojo) {
        this.t = abstractPojo;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object invokeResult = method.invoke(t, args);
        if (method.getName().startsWith("set") && method.getAnnotation(Performance.class) != null) {
            t.updateModifyFlag();
        }
        return invokeResult;
    }
}
